package com.googlecode.project.tests;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class DeleteTest {

	public static void main(String[] args) {
		System.out.println("An example for Deleting a Row from a Database!");
		Connection con = null;
		String url = "jdbc:derby:/DerbyDB/AssetDB";
		String driver = "org.apache.derby.jdbc.EmbeddedDriver";
		int query;
		try {
			Class.forName(driver);
			con = DriverManager.getConnection(url);
			try {
				Statement st = con.createStatement();
				Scanner sc = new Scanner(System.in);
				System.out.println("Enter the query you want removed!");
				query = sc.nextInt();
				String sql = "DELETE FROM Requests_Copy WHERE Query_ID = " + query;
				int delete = st.executeUpdate(sql);
				if (delete == 1) {
					System.out.println("Row is deleted.");
				} else {
					System.out.println("Row is not deleted.");
				}
			} catch (SQLException s) {
				System.out.println("SQL statement is not executed!");
				System.out.println(s.getMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
